//
//  NewsService.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/8.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "NewsService.h"

#import "ArticleIndexAPI.h"
#import "ArticleDetailAPI.h"
#import "ArticleLikeAPI.h"
#import "ArticleCommentAPI.h"
#import "ArticleListAPI.h"

@implementation NewsService

/**
 获取首页资讯
 */
+ (void)fetchNewsDataWithResult:(void (^)(id _Nonnull))callback {
    ArticleIndexAPI *api = [[ArticleIndexAPI alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        callback(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        callback(request.responseObject);
    }];
}


/**
 获取资讯列表
 
 @param page 分页
 @param callback call back
 */
+ (void)fetchNewsListWithPage:(NSInteger)page callback:(void (^)(id _Nonnull))callback {
    ArticleListAPI *api = [[ArticleListAPI alloc] init];
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"page"] = @(page);
    mdic[@"token"] = User_Token;
    api.outerParameters = mdic;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        callback(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        callback(request.responseObject);
    }];
}

/**
 获取资讯详情

 @param article_id 资讯id
 @param callback callback
 */
+ (void)fetchNewsDetailWithId:(NSString *)article_id callback:(void (^)(ResponseModel * _Nonnull))callback {
    ArticleDetailAPI *api = [[ArticleDetailAPI alloc] init];
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"id"] = article_id;
    mdic[@"token"] = User_Token;
    api.outerParameters = mdic;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        ResponseModel *responseData = [ResponseModel yy_modelWithJSON:request.responseObject];
        callback(responseData);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        
    }];
}



/**
 用户点赞

 @param msg_id 消息id
 @param news_id 资讯id
 @param complete callback
 */
+ (void)likeHandleWithMsgId:(NSString *)msg_id andNewsId:(NSString *)news_id Completion:(void (^)(BOOL))complete {
    ArticleLikeAPI *api = [[ArticleLikeAPI alloc] init];
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"token"] = User_Token;
    mdic[@"msg_id"] = msg_id;
    mdic[@"news_id"] = news_id;
    api.outerParameters = mdic;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(false);
    }];
}


/**
 用户评论

 @param msg 评论内容
 @param news_id 新闻id
 @param complete call back
 */
+ (void)addCommentWithMsg:(NSString *)msg andNewsId:(NSString *)news_id Completion:(void (^)(BOOL))complete {
    ArticleCommentAPI *api = [[ArticleCommentAPI alloc] init];
    NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
    mdic[@"token"] = User_Token;
    mdic[@"msg"] = msg;
    mdic[@"news_id"] = news_id;
    api.outerParameters = mdic;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(false);
    }];
}

@end
